<template>
  <ma-crud ref="crudRef" :columns="columns" :options="crud">
    <template #search-categoryName="{ searchForm, component }">
      <a-input
        v-model.trim="searchForm[component.dataIndex]"
        :style="{ width: '240px' }"
        allow-clear
        placeholder="请输入分类名称"
      >
        <template #prefix>
          <icon-search />
        </template>
      </a-input>
    </template>
  </ma-crud>
</template>

<script lang="ts" name="Category" setup>
import { addWfCategory, delWfCategory, listWfCategory, updateWfCategory } from "@/api/workflow/category";

const crud = reactive({
  id: "categoryId",
  pk: "categoryId",
  title: "分类查询",
  formLayout: "vertical",
  formOption: {
    width: 600,
    layout: [
      {
        formType: "grid",
        gutter: 16,
        cols: [
          { span: 12, formList: [{ dataIndex: "categoryName" }] },
          { span: 12, formList: [{ dataIndex: "code" }] },
          { span: 24, formList: [{ dataIndex: "remark" }] }
        ]
      }
    ]
  },
  api: listWfCategory,
  showIndex: true,
  operationColumn: true,
  operationColumnAlign: "center",
  operationColumnWidth: 160,
  pageLayout: "normal",
  requestParams: { orderBy: "createTime", orderType: "desc" },
  add: { api: addWfCategory, auth: ["system:wfCategory:add"], text: "新增", show: true },
  edit: { api: updateWfCategory, auth: ["system:wfCategory:edit"], text: "编辑", show: true },
  delete: { api: delWfCategory, auth: ["system:wfCategory:delete"], text: "删除", show: true }
});

const columns = reactive([
  {
    title: "分类编号",
    dataIndex: "categoryId",
    align: "center",
    hide: true
  },
  {
    title: "分类名称",
    dataIndex: "categoryName",
    align: "center",
    search: true,
    commonRules: {
      required: true,
      message: "请输入分类名称"
    }
  },
  {
    title: "分类编码",
    dataIndex: "code",
    align: "center",
    commonRules: {
      required: true,
      message: "请输入分类编码"
    }
  },
  {
    title: "描述",
    dataIndex: "remark",
    align: "center",
    formType: "textarea",
    autoSize: { minRows: 3, maxRows: 6 },
    maxLength: 200,
    showWordLimit: true
  },
  {
    title: "创建时间",
    dataIndex: "createTime",
    align: "center",
    addDisplay: false,
    editDisplay: false
  }
]);
</script>
